<template>
  <div class="app-container">
    <el-card class="card-form">
      <div class="expert-title">评审任务</div>
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="任务名称" prop="taskName">
          <el-input
            v-model="queryParams.taskName"
            placeholder="请输入"
            clearable
            size="small"
            style="width: 252px"
            maxlength="30"
          />
        </el-form-item>
        <el-form-item label="任务创建时间" prop="createTime">
          <el-date-picker
            v-model="dateRange"
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="changeDate">
          </el-date-picker>
        </el-form-item>
        <!-- <el-form-item label="任务节点" prop="node">
          <el-select
            v-model="queryParams.node"
            placeholder="请选择"
            clearable
            size="small"
            style="width: 252px"
          >
            <el-option
              v-for="dict in nodeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" size="small" @click="handleQuery"
            >查询</el-button
          >
          <el-button size="small" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="card-table">
      <status-bar :status="processingStatusMap" @change="onChangeProcessingStatus"></status-bar>
      <el-table v-loading="loading" :data="reviewTasktList" border>
        <el-table-column label="序号" align="center" type="index" width="65" />
        <el-table-column
          label="任务名称"
          align="center"
          prop="taskName"
          :show-overflow-tooltip="true"
          width="612"
        />
        <el-table-column
          label="任务创建时间"
          align="center"
          prop="createTime"
          :show-overflow-tooltip="true"
        />
        <el-table-column label="任务状态" align="center" prop="nodeStatus">
          <template slot-scope="scope">
            <span class="icon-state" :class="scope.row.nodeName|getIconClass"><span></span></span>
            <span>{{scope.row.nodeName}}</span>
            <!-- <span style="margin-left: 10px">{{
              scope.row.nodeStatus == "-1"
                ? "待提交"
                : scope.row.nodeStatus == "0"
                ? "已提交"
                : scope.row.nodeStatus == "1"
                ? "待审核"
                : scope.row.nodeStatus == "2"
                ? "已通过"
                : scope.row.nodeStatus == "7"
                ? "待抽取专家"
                : scope.row.nodeStatus == "9"
                ? "待接受任务"
                : scope.row.nodeStatus == "11"
                ? "待审批"
                : scope.row.nodeStatus == "13"
                ? "待审批"
                : scope.row.nodeStatus == "15"
                ? "退回重申"
                : scope.row.nodeStatus == "30"
                ? "待提交"
                : scope.row.nodeStatus == "32"
                ? "待提交"
                : scope.row.nodeStatus == "41"
                ? "待考评"
                : scope.row.nodeStatus
            }}</span> -->
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="handleView(scope.row)" v-show="scope.row.nodeName === '待处理'"
              >审批</el-button
            >
            <el-button
              size="mini"
              type="text"
              @click="handleView(scope.row)"
              v-show="scope.row.nodeName == '已处理'"
              >查看详情</el-button
            >
            <el-button
              size="mini"
              type="text"
              @click="handleDelete(scope.row)"
              v-show="scope.row.nodeName == '通过'"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        v-show="total > 0"
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-size="queryParams.pageSize"
        :current-page="queryParams.pageNum"
        :page-sizes="[10, 20, 30, 50, 100]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>
<script>
import { listThird, delTask, getTask } from "@/api/tripartiteReview/reviewTask";
import { getStatusDicts } from "@/api/projectCompany/myProject";
import StatusBar, { mapToDict } from '@/views/components/statusBar';
function getIconClass(isStateName) {
  switch(isStateName) {
    case '待处理':
      return 'icon-orange';
    case '已处理':
      return 'icon-blue';
    default:
      return 'icon-default';
  }
}
export default {
  name: "Expert",
  components: {
    StatusBar,
  },
  filters: {
    getIconClass,
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 专家表格数据
      reviewTasktList: [
        {
          roleId: "01",
          roleName: "胡涛华",
          roleKey: "计算机",
          roleSort: "计算机",
          roleSort: "重庆市渝北",
          nodeStatus: "待抽取专家",
        },
      ],
      // 总条数
      total: 1,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        createTime: undefined,
        taskName: undefined,
        node: undefined,
        nodeStatus: undefined,
      },
      // 日期范围
      dateRange: [],
      // 任务节点
      nodeOptions: [],
      // 任务状态
      statusOptions: [],
      processingStatusMap: mapToDict([
        ['all', '全部'],
        ['0', '待处理'],
        ['1', '已处理'],
      ]),
      processingStatusQuery: {},
    };
  },
  created() {
    this.getList();
    this.getDicts("third_node_status").then((response) => {
      this.nodeOptions = response.data;
    });
    getStatusDicts().then((response) => {
      this.statusOptions = response.data;
    });
  },
  methods: {
    /** 格式化日期 */
    changeDate(val){
      console.log(val);
      if(val){
        this.queryParams.starTime=val[0]+ " 00:00:00"
        this.queryParams.endTime=val[1]+ " 23:59:59"
      }else{
        this.queryParams.starTime=undefined
        this.queryParams.endTime=undefined
      }
    },
    /** 查询评审任务列表 */
    getList(query) {
      this.loading = true;
      listThird({
        ...this.queryParams,
        ...this.processingStatusQuery,
        ...query,
      }).then((response) => {
        this.reviewTasktList = response.list;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.dateRange=[];
      this.queryParams.starTime=undefined
      this.queryParams.endTime=undefined
      this.handleQuery();
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.$router.push({
        path: "/tripartiteReview/reviewTask/reviewTaskView",
        query: { reviewTaskId: row.reviewTaskId },
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const reviewTaskId = row.reviewTaskId;
      this.$confirm("是否确认删除 ？", "删除", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "del_box",
      })
        .then(function () {
          return delTask(reviewTaskId);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    /** 分页 */
    handleSizeChange(val) {
      this.queryParams.pageSize = val;
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleCurrentChange(val) {
      this.queryParams.pageNum = val;
      this.getList();
    },
    onChangeProcessingStatus(query) {
      this.processingStatusQuery = query;
      this.queryParams.pageNum = 1;
      this.getList(query);
    }
  },
};
</script>
<style scoped lang="scss">
.expert-title {
  font-size: 18px;
  font-family: PingFang SC, PingFang SC-Medium;
  font-weight: 500;
  margin-bottom: 24px;
  color: #000000;
}
.card-table {
  margin-top: 10px;
  .el-pagination {
    text-align: center;
    margin-top: 40px;
  }
  // 状态样式
  .icon-state {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 16px;
    position: relative;
    top: 3.5px;
    margin-right: 10px;
    span {
      display: inline-block;
      margin: 5px;
      width: 7px;
      height: 7px;
      border-radius: 16px;
    }
  }
  .icon-blue {
    background: rgba(49, 113, 238, 0.1);
    span {
      background: #3171ee;
    }
  }
  .icon-red {
    background: rgba(223, 32, 66, 0.1);
    span {
      background: #df2042;
    }
  }
  .icon-green {
    background: rgba(51, 168, 61, 0.1);
    span {
      background: #33a83d;
    }
  }
  .icon-orange {
    background: rgba(223, 130, 45, 0.1);
    span {
      background: #df822d;
    }
  }
}
</style>
<style lang="scss">
.card-form {
  .el-card__body {
    padding-bottom: 0;
  }
  label {
    font-weight: normal !important;
  }
  .el-form--inline .el-form-item {
    margin-right: 32px;
  }
}
.card-table {
  .el-card__body {
    padding: 20px;
  }
}
/* 删除弹出框样式 */
.del_box {
  width: 345px;
  height: 175px;
  .el-message-box__headerbtn {
    background: url("../../../assets/images/icon_dialog_close.png");
    background-size: 100%;
    width: 16px;
    height: 16px;
    .el-message-box__close {
      visibility: hidden;
    }
  }
  .el-message-box__content {
    padding: 26px 95px;
    font-size: 16px;
    .el-message-box__status.el-icon-warning {
      color: #ea4747;
    }
    .el-message-box__status + .el-message-box__message {
      padding-right: 0;
    }
  }
}
</style>
